class Solution:
    def minimumTotal(self, triangle) -> int:
        r = triangle[-1]
        for i in range(len(triangle)-2, -1, -1):
            tmp = []
            for j in range(len(triangle[i])):
                tmp.append(min(r[j], r[j+1]) + triangle[i][j])
            r = tmp
        return r[0]


if __name__ == '__main__':
    so = Solution()
    t = [
        [2]
    ]
    r = so.minimumTotal(t)
    print(r)
